﻿using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Dragon.Library.Utility
{
    public sealed class FileUtility
    {
        public static void Save(byte[] file, string savePatch)
        {
            var fileStream = new FileStream(savePatch, FileMode.OpenOrCreate);
            fileStream.Write(file, 0, file.Length);
            fileStream.Close();
            fileStream.Dispose();
        }

        public static void Delete(string savePatch)
        {
            File.Delete(savePatch);
        }

        public static void CreateDirectoryPath(string directoryPath)
        {
            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
        }

        public static string[] GetDirectories(string patch)
        {
            return Directory.GetDirectories(patch);
        }

        public static string[] GetFiles(string patch)
        {
            return Directory.GetFiles(patch);
        }

        public static string[] GetFileNames(string patch)
        {
            IList<string> fileNames = new List<string>();
            DirectoryInfo source = new DirectoryInfo(patch);
            foreach (FileInfo diSourceSubDir in source.GetFiles())
            {
                fileNames.Add(diSourceSubDir.Name);
            }
            return fileNames.ToArray();
        }
    }
}
